import java.lang.reflect.Array;

public class Reverse {
	public static int[] reverse(int[] arr) {
		int m = 0,n = 0;
		for(int i = 1;i < arr.length;i++){
			if(arr[i-1] < arr[i]){
				m = i;
			}
		}
		System.out.println("m"+m);
		
		for(int i = m;i < arr.length;i++){
			if(arr[m - 1] < arr[i]){
				n = i;
			}
		}
		System.out.println("n"+n);
		
		int tmp = arr[m-1];
		arr[m-1] = arr[n];
		arr[n] = tmp;
		for(int i = 0;i< arr.length;i++){
			System.out.print(arr[i]);
		}
		System.out.println();
		
		int len = arr.length-1;
		for(int i = m;i < (m+arr.length)/2;){
			tmp = arr[i];
			arr[i] = arr[len];
			arr[len] = tmp;
			i++;
			len--;
		}
		return arr;
	}
	public static void main(String[] args) {
		int[] arr = new int[5];
		arr[0] = 3;
		arr[1] = 5;
		arr[2] = 4;
		arr[3] = 2;
		arr[4] = 1;
		int[] a = reverse(arr);
		for(int i = 0;i< a.length;i++){
			System.out.print(a[i]);
		}
	}

}
